<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta property="og:type" content="website">
<meta property="og:title" content="smallmuou&#39;s blog">
<meta property="og:url" content="http://smallmuou.gitee.io/blog/page/9/index.html">
<meta property="og:site_name" content="smallmuou&#39;s blog">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="smallmuou&#39;s blog">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://smallmuou.gitee.io/blog/page/9/"/>





  <title>smallmuou's blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">smallmuou's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"><a href="https://github.com/smallmuou">https://github.com/smallmuou</a></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/04/06/2017-04-06-lighttpd支持HTTPS/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/04/06/2017-04-06-lighttpd支持HTTPS/" itemprop="url">lighttpd支持HTTPS</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-04-06T00:00:00+08:00">
                2017-04-06
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/后端/" itemprop="url" rel="index">
                    <span itemprop="name">后端</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>随着Apple、Google大力推广HTTPS，HTTPS将成为今后网站的主流，而前段时间正好看到<a href="https://letsencrypt.org/" target="_blank" rel="noopener">Let’s Encrypt</a>可以生成免费的SSL证书。因此尝试配置了下lighttpd，发现非常容易，大体步骤如下:</p>
<h2 id="申请证书"><a href="#申请证书" class="headerlink" title="申请证书"></a>申请证书</h2><h4 id="1-获取Certbot"><a href="#1-获取Certbot" class="headerlink" title="1. 获取Certbot"></a>1. 获取Certbot</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone https://github.com/certbot/certbot</span><br></pre></td></tr></table></figure>
<h4 id="2-申请证书"><a href="#2-申请证书" class="headerlink" title="2. 申请证书"></a>2. 申请证书</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd certbot</span><br><span class="line">./letsencrypt-auto certonly -d smallmuou.xyz</span><br></pre></td></tr></table></figure>
<p>PS: 选择Automatically use a temporary webserver(stadalone)</p>
<h4 id="3-配置证书"><a href="#3-配置证书" class="headerlink" title="3. 配置证书"></a>3. 配置证书</h4><p>成功后，会生成如下几个文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">smallmuou:~ $ tree /etc/letsencrypt/live/smallmuou.xyz/</span><br><span class="line">/etc/letsencrypt/live/smallmuou.xyz/</span><br><span class="line">|-- cert.pem -&gt; ../../archive/smallmuou.xyz/cert1.pem</span><br><span class="line">|-- chain.pem -&gt; ../../archive/smallmuou.xyz/chain1.pem</span><br><span class="line">|-- fullchain.pem -&gt; ../../archive/smallmuou.xyz/fullchain1.pem</span><br><span class="line">|-- privkey.pem -&gt; ../../archive/smallmuou.xyz/privkey1.pem</span><br><span class="line">|-- README</span><br></pre></td></tr></table></figure>
<p>PS: 各个文件的含义可以查看README的说明，我也给出我的理解</p>
<ul>
<li>cert.pem 公钥</li>
<li>prikey.pem 私钥</li>
<li>fullchain.pem CA证书信任链 (包含Root Certificate)</li>
<li>chain.pem 上一级CA证书（这里指Let’s Encrypt）</li>
</ul>
<p>PS: 可以通过<code>cat cert.pem prikey.pem &gt; server.pem</code>将私有和公用打包在一起，以供后续lighttpd配置使用.</p>
<p>信任链（chain）即证书的信任关系，如A信任A1，A1信任A2，其中最顶级的节点就是根证书（root certificate），Let’s Encrypt就是直接隶属于root certificate. </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">└── DST Root CA X3</span><br><span class="line">    └── Let&apos;s Encrypt Authority X3</span><br><span class="line">        └── smallmuou.xyz</span><br></pre></td></tr></table></figure>
<h2 id="安装及配置lighttpd"><a href="#安装及配置lighttpd" class="headerlink" title="安装及配置lighttpd"></a>安装及配置lighttpd</h2><h4 id="1-安装SSL"><a href="#1-安装SSL" class="headerlink" title="1. 安装SSL"></a>1. <a href="https://redmine.lighttpd.net/projects/1/wiki/docs_ssl#How-to-install-SSL" target="_blank" rel="noopener">安装SSL</a></h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install openssl*</span><br></pre></td></tr></table></figure>
<h4 id="2-下载"><a href="#2-下载" class="headerlink" title="2. 下载"></a>2. 下载</h4><p>进入<a href="http://www.lighttpd.net/" target="_blank" rel="noopener">lighttpd官网</a>，下载lighttpd源码包</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.45.tar.gz</span><br></pre></td></tr></table></figure>
<h4 id="3-解压并编译"><a href="#3-解压并编译" class="headerlink" title="3. 解压并编译"></a>3. 解压并编译</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">tar xzvf lighttpd-1.4.45.tar.gz</span><br><span class="line">cd lighttpd-1.4.45</span><br><span class="line">./autogen.sh</span><br><span class="line">./configure --with-openssl --with-openssl-libs=/usr/lib</span><br><span class="line">make </span><br><span class="line">make install</span><br></pre></td></tr></table></figure>
<p>PS: 安装完后，执行<code>lighttpd -v</code>，当有出现(ssl)字样，则表示lighttpd已支持SSL</p>
<h4 id="4-配置"><a href="#4-配置" class="headerlink" title="4. 配置"></a>4. 配置</h4><p>进入<code>doc/config</code>编辑lighttpd.conf文件，添加如下内容</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">$SERVER[&quot;socket&quot;] == &quot;0.0.0.0:443&quot; &#123;</span><br><span class="line">  ssl.engine                  = &quot;enable&quot;</span><br><span class="line">  ssl.pemfile                 = &quot;/etc/letsencrypt/live/smallmuou.xyz/server.pem&quot;</span><br><span class="line">  ssl.ca-file                 = &quot;/etc/letsencrypt/live/smallmuou.xyz/fullchain.pem&quot;</span><br><span class="line">  server.document-root        = &quot;/srv/www/htdocs&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>ssl.engine 是否开启SSL</li>
<li>ssl.pemfile pem文件位置（包含私有和公用）</li>
<li>ssl.ca-file CA证书</li>
<li>server.document-root 根路径<br>点击<a href="https://redmine.lighttpd.net/projects/1/wiki/docs_ssl#How-to-install-SSL" target="_blank" rel="noopener">此处</a>查看更多选项内容</li>
</ul>
<h4 id="5-完成"><a href="#5-完成" class="headerlink" title="5. 完成"></a>5. 完成</h4><p>经过以上步骤，重新启动<code>lighttpd -f lighttpd.conf</code>，就可以使用https访问，而且是受信任的. 亲测有效.</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/03/24/2017-03-24-TCP状态图/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/03/24/2017-03-24-TCP状态图/" itemprop="url">TCP状态图</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-03-24T00:00:00+08:00">
                2017-03-24
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/运维/" itemprop="url" rel="index">
                    <span itemprop="name">运维</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>在使用netstat发现有个State字段，于是脑补了下，发现水还是蛮深的，以前只了解三次握手、四次握手，并没有了解其中的状态，现在有幸能够接触，大家可以直接Google搜索<code>TCP状态图</code>，会出现经典的状态图，如下：</p>
<p><img src="http://www.cnitblog.com/images/cnitblog_com/wildon/544465b00200001s.png" alt="image"></p>
<p>我这里将对其进行整理，方便大家理解，看图前，先看下后面用到的术语：</p>
<ul>
<li>S - 表示发送</li>
<li>R - 表示接收</li>
</ul>
<h2 id="连接建立阶段（三次握手）"><a href="#连接建立阶段（三次握手）" class="headerlink" title="连接建立阶段（三次握手）"></a>连接建立阶段（三次握手）</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">CLOSED                                 ESTABLISH</span><br><span class="line">  |                                        |</span><br><span class="line">  |---------------- CLIENT ----------------|</span><br><span class="line">  |                                        |</span><br><span class="line">  |           SYN_SEND                     |</span><br><span class="line">  |              |                         |</span><br><span class="line">  |              |       R: SYN ACK        |</span><br><span class="line">  |-------------&gt;|------------------------&gt;|</span><br><span class="line">  |    S: SYN    |          S: ACK         |</span><br><span class="line">  |              |                         |</span><br><span class="line">  |                                        |</span><br><span class="line">  |                                        |</span><br><span class="line">  |                                        |</span><br><span class="line">  |---------------- SERVER ----------------|</span><br><span class="line">  |                                        |</span><br><span class="line">  |           LISTEN        SYN_RECV       |</span><br><span class="line">  |              |              |          |</span><br><span class="line">  |     OPEN     |    R: SYN    |  R: ACK  |</span><br><span class="line">  |-------------&gt;|-------------&gt;|---------&gt;|</span><br><span class="line">  |              |  S: SYN ACK  |          |</span><br><span class="line">  |              |              |          |</span><br><span class="line">  |              |    R: RST    |          |</span><br><span class="line">  |              |&lt;-------------|          |</span><br><span class="line">  |              |              |          |</span><br></pre></td></tr></table></figure>
<ul>
<li>CLIENT - 客户端</li>
<li>SERVER - 服务端</li>
<li>CLOSED - 关闭态</li>
<li>ESTABLISH - 连接态</li>
<li>LISTEN - 监听态（被动打开）</li>
<li>SYN_SEND - SYN发送态（已发送SYN）</li>
<li>SYN_RECV - SYN接收态（已接收SYN，并发送ACK）</li>
<li>三次握手: 客户端发送SYN -&gt; 服务端接收SYN，并发送SYN、ACK –&gt;  客户端接收SYN、ACK，并发送ACK</li>
<li>RST - 复位指令，SYN_RECV在接收到RST可以回到LISTEN，主要用于处理异常连接，至于什么情况会出现RST，可以点击此<a href="https://my.oschina.net/costaxu/blog/127394" target="_blank" rel="noopener">传送门</a></li>
</ul>
<h2 id="连接释放阶段（四次握手）"><a href="#连接释放阶段（四次握手）" class="headerlink" title="连接释放阶段（四次握手）"></a>连接释放阶段（四次握手）</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">ESTABLISH                                        CLOSED</span><br><span class="line">  |                                                 |</span><br><span class="line">  |--------------------- ACTIVE --------------------|</span><br><span class="line">  |                                                 |</span><br><span class="line">  |         FIN_WAIT_1   FIN_WAIT_2  TIME_WAIT      |</span><br><span class="line">  |              |            |          |          |</span><br><span class="line">  |              |   R: ACK   |  R: FIN  |   2MSL   |</span><br><span class="line">  |-------------&gt;|-----------&gt;|---------&gt;|---------&gt;|</span><br><span class="line">  |    S: FIN    |            |  S: ACK  |          |</span><br><span class="line">  |              |            |          |          |</span><br><span class="line">  |              |            |          |          |</span><br><span class="line">  |              |     R: FIN ACK        |          |</span><br><span class="line">  |              |----------------------&gt;|          |</span><br><span class="line">  |              |       S: ACK          |          |</span><br><span class="line">  |              |                       |          |</span><br><span class="line">  |              |                       |          |</span><br><span class="line">  |              |         CLOSING       |          |</span><br><span class="line">  |              |   R: FIN   |  R:ACK   |          |</span><br><span class="line">  |              |-----------&gt;|---------&gt;|          |</span><br><span class="line">  |              |   S: ACK   |          |          |</span><br><span class="line">  |                                                 |</span><br><span class="line">  |                                                 |</span><br><span class="line">  |-------------------- PASSIVE --------------------|</span><br><span class="line">  |                                                 |</span><br><span class="line">  |          CLOSE_WAIT     LAST_ACK                |</span><br><span class="line">  |              |              |                   |</span><br><span class="line">  |    R: FIN    |              |      R: ACK       |</span><br><span class="line">  |-------------&gt;|-------------&gt;|------------------&gt;|</span><br><span class="line">  |    S: ACK    |    S: FIN    |                   |</span><br><span class="line">  |              |              |                   |</span><br></pre></td></tr></table></figure>
<ul>
<li>ACTIVE - 主动方</li>
<li>PASSIVE - 被动方</li>
<li>CLOSED - 关闭态</li>
<li>ESTABLISH - 连接态</li>
<li>FIN_WAIT_1 - 主动发送FIN</li>
<li>CLOSE_WAIT - 收到FIN，并发送ACK</li>
<li>FIN_WAIT_2 - 主动发送FIN后，并接收到ACK</li>
<li>LAST_ACK - 被动方进入CLOSE_WAIT后，再次发送FIN</li>
<li>CLOSING - 当发出FIN的时候同时收到FIN，则进入CLOSING态（同时关闭）</li>
<li>TIME_WAIT - 等待结束态</li>
<li>2MSL - 2倍报文最大生存时间，为什么需要2倍，因为当被动方发现收不到ACK，则会重发FIN，因此需要等待2倍MSL来预留需要再次发送ACK的时间</li>
<li>四次握手：主动方发送FIN -&gt; 被动方接收FIN，并发送ACK -&gt; 被动方发送FIN -&gt; 主动方接收FIN，并发送ACK </li>
</ul>
<h2 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h2><p>另外，分享一篇文章《<a href="http://coolshell.cn/articles/11564.html" target="_blank" rel="noopener">TCP 那些事</a>》</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/03/24/2017-03-24-netstat命令/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/03/24/2017-03-24-netstat命令/" itemprop="url">netstat命令</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-03-24T00:00:00+08:00">
                2017-03-24
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/SHELL/" itemprop="url" rel="index">
                    <span itemprop="name">SHELL</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>如果你需要获取一些网络信息，如路由表、端口、连接数，一个netstat足以；以前我经常使用专门的工具来做这些，比如route、lsof等.后面对netstat进行学习，发现非常好用.</p>
<h3 id="入门"><a href="#入门" class="headerlink" title="入门"></a>入门</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">netstat [options]</span><br></pre></td></tr></table></figure>
<ul>
<li>options（常用）<ul>
<li>-a 显示所有链接的socket</li>
<li>-n 直接显示IP</li>
<li>-l 只显示监听的socket</li>
<li>-t 只显示tcp</li>
<li>-r 查看路由表</li>
<li>-u 只显示udp</li>
<li>-p 显示哪个进程</li>
<li>-s 统计</li>
</ul>
</li>
</ul>
<h3 id="输出"><a href="#输出" class="headerlink" title="输出"></a>输出</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">Active Internet connections (w/o servers)</span><br><span class="line">Proto Recv-Q Send-Q Local Address           Foreign Address         State      </span><br><span class="line">tcp        0      0 45.76.196.191.vul:41630 nrt12s13-in-f206.:https ESTABLISHED</span><br><span class="line">...</span><br><span class="line">Active UNIX domain sockets (w/o servers)</span><br><span class="line">Proto RefCnt Flags       Type       State         I-Node   Path</span><br><span class="line">unix  2      [ ]         DGRAM                    9552     /run/systemd/shutdownd</span><br><span class="line">...</span><br></pre></td></tr></table></figure>
<p>显示包含2部分，一个是网络socket，一个是本地socket（程序内部通信）</p>
<h3 id="常用组合"><a href="#常用组合" class="headerlink" title="常用组合"></a>常用组合</h3><ul>
<li>查看路由表<code>netstat -r</code></li>
<li>查看监听端口<code>netstat -ltp</code></li>
<li>查看对外连接<code>netstat -ntp</code></li>
</ul>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/03/22/2017-03-22-集成DISQUS评论/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/03/22/2017-03-22-集成DISQUS评论/" itemprop="url">集成DISQUS评论</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-03-22T00:00:00+08:00">
                2017-03-22
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/其他/" itemprop="url" rel="index">
                    <span itemprop="name">其他</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>今天突然收到多说发来的邮件：多说即将关闭服务，原文如下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">重要通知: 多说即将关闭</span><br><span class="line">多说网 发表于 20小时前</span><br><span class="line">因公司业务调整，非常遗憾的向大家宣布多说项目即将关闭。 我们将于2017年6月1日正式关停服务，在此之前您可以通过后台的数据导出功能导出自己站点的评论数据。 对此给您造成的不便，我们深表歉意，感谢您的一路相伴。</span><br></pre></td></tr></table></figure>
<p>想了想发现我的blog还在用多说，那么只能切换，谁叫免费喽。先前有了解到国外的DISQUS，界面比多说好看，只是碍于墙，所以一直没有切换，现在迫不得已，需要评论的自行找梯子，下面我来说下基于Jekyll网站DISQUS集成方法.</p>
<h3 id="1-注册登录DISQUS"><a href="#1-注册登录DISQUS" class="headerlink" title="1. 注册登录DISQUS"></a>1. 注册登录DISQUS</h3><p><a href="https://disqus.com/" target="_blank" rel="noopener">DISQUS传送门</a></p>
<h3 id="2-安装"><a href="#2-安装" class="headerlink" title="2. 安装"></a>2. 安装</h3><p>进入此<a href="https://disqus.com/admin/install" target="_blank" rel="noopener">传送门</a>，选择Jekyll，进入后，找到<code>Universal Embed Code</code>，并复制其中的代码到_layouts/post.html，可以查考我另外一篇文章《为博客添加 多说 评论》</p>
<h3 id="3-完成"><a href="#3-完成" class="headerlink" title="3. 完成"></a>3. 完成</h3>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/03/21/2017-03-21-命令行下高性能的JSON工具/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/03/21/2017-03-21-命令行下高性能的JSON工具/" itemprop="url">命令行下高性能的JSON工具</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-03-21T00:00:00+08:00">
                2017-03-21
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/SHELL/" itemprop="url" rel="index">
                    <span itemprop="name">SHELL</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>作为一个命令行控，希望一切都能够在命令行下完成，当然也包括JSON。JSON作为新时代的通信方式，深受API爱好者的欢迎，因此我也希望能够在命令行下操作JSON。要实现在命令行操作JSON（解码、编码），首先想到的当然就是利用python提供的json库写一个python脚本，于是动手，并且很快实现（python毕竟就是快），在普通pc上可谓流畅，后面迁移到树莓派上，发现慢的要命，即使是非常简单的json，也要解析个2s以上，果断放弃，于是继续征途…</p>
<h3 id="jo"><a href="#jo" class="headerlink" title="jo"></a>jo</h3><p>经过一番搜索，发现有个<a href="https://github.com/jpmens/jo" target="_blank" rel="noopener">jo工具</a>，可以非常方便的编码JSON，而且可以认为是专门为bash而设计的，看下面几个例子就知道：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">osmc@osmc:~$ jo os=linux version=3.0</span><br><span class="line"></span><br><span class="line">&#123;&quot;os&quot;:&quot;linux&quot;,&quot;version&quot;:3&#125;</span><br></pre></td></tr></table></figure>
<p>级联</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">osmc@osmc:~$ jo sys=$(jo -a $(jo os=linux version=3.0) $(jo os=unix version=4.0))</span><br><span class="line"></span><br><span class="line">&#123;&quot;sys&quot;:[&#123;&quot;os&quot;:&quot;linux&quot;,&quot;version&quot;:3&#125;,&#123;&quot;os&quot;:&quot;unix&quot;,&quot;version&quot;:4&#125;]&#125;</span><br></pre></td></tr></table></figure>
<p>从上述可以看成使用极为简单，而且可以级联，另外最重要的一点就是效率非常高，但是jo仅仅只是一个编码工具，解码呢，于是我继续搜索，发现有个<a href="https://github.com/stedolan/jq" target="_blank" rel="noopener">jq工具</a>，可以实现解析，但是发现效率太低了，跟我直接用python没什么区别，于是继续搜索…</p>
<h3 id="jshon"><a href="#jshon" class="headerlink" title="jshon"></a>jshon</h3><p>又经过一番努力，发现了新大陆 —— <a href="https://github.com/keenerd/jshon.git" target="_blank" rel="noopener">jshon</a>，他是基于jansson，效率自然不用说。于是试用了下，效率非常高。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[osmc@osmc:~$ jo os=linux version=3.0|jshon -e os</span><br><span class="line"></span><br><span class="line">&quot;linux&quot;</span><br></pre></td></tr></table></figure>
<p>有了以上的两个工具，在命令行的世界里，我们也可以愉快地使用JSON</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/03/20/2017-03-20-KODI JSON-RPC解读/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/03/20/2017-03-20-KODI JSON-RPC解读/" itemprop="url">KODI JSON-RPC解读</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-03-20T00:00:00+08:00">
                2017-03-20
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/树莓派/" itemprop="url" rel="index">
                    <span itemprop="name">树莓派</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>大概一年前就开始关注KODI了，确实是个非常不错的开源项目，KODI提供很好的操作界面，但作为一个命令行控或者是没有显示屏的树莓派，我希望能够通过命令行对其进行控制，比如播放、暂停、静音等等. 于是去搜索了下，发现有个JSON-RPC，他是kODI官网推出的，方便其他开发者对接，到目前为止已经更新到v8，可以点击<a href="http://kodi.wiki/view/JSON-RPC_API" target="_blank" rel="noopener">这里查看</a>。这里将为大家详细介绍下它的用法。</p>
<h3 id="初步印象"><a href="#初步印象" class="headerlink" title="初步印象"></a>初步印象</h3><p>在使用JSON-RPC，必须开启，可以进入设置 - 服务 - 控制，开启服务，可设置端口、用户名、密码，当然可以不设置用户名和密码</p>
<h3 id="入门"><a href="#入门" class="headerlink" title="入门"></a>入门</h3><p>JSON-RPC顾名思义就是采用JSON进行RPC通信，那么它的<a href="http://www.jsonrpc.org/specification" target="_blank" rel="noopener">基本格式</a>如下：</p>
<h5 id="请求-REQUEST"><a href="#请求-REQUEST" class="headerlink" title="请求(REQUEST)"></a>请求(REQUEST)</h5><ul>
<li>URI：<a href="http://host:port/jsonrpc" target="_blank" rel="noopener">http://host:port/jsonrpc</a></li>
<li>METHOD：POST</li>
<li>HEADER：ContentType:application/json</li>
<li>BODY: {“jsonrpc”:”2.0”, “method”:”xx”, “params”:{}, “id”:xx},jsonrpc必须是2.0，这个与实际版本无关 method为具体方法，会在后面介绍，params为method对应的参数，若无，则可以不传 id是由客户端定义，用于标识客户端，服务器会返回相同的id（见响应）</li>
</ul>
<p>如：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -X POST -H &quot;ContentType:application/json&quot; -d &apos;&#123;&quot;jsonrpc&quot;: &quot;2.0&quot;, &quot;method&quot;: &quot;JSONRPC.Version&quot;, &quot;id&quot;:&quot;22&quot;&#125;&apos; http://localhost:8080/jsonrpc</span><br></pre></td></tr></table></figure>
<h5 id="响应-RESPONSE"><a href="#响应-RESPONSE" class="headerlink" title="响应(RESPONSE)"></a>响应(RESPONSE)</h5><ul>
<li>BODY:  {“jsonrpc”:”2.0”, “result”:”xxx”,”error”:{“code”:xx,”message”:”xxx”,”data”:”xxx”},”id”:xx }  result为返回结果，若错误，则空，error错误，id为请求传递的，若错误，为空</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123;&quot;id&quot;:&quot;22&quot;,&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;result&quot;:&#123;&quot;version&quot;:&#123;&quot;major&quot;:8,&quot;minor&quot;:0,&quot;patch&quot;:0&#125;&#125;&#125;</span><br></pre></td></tr></table></figure>
<h3 id="进阶"><a href="#进阶" class="headerlink" title="进阶"></a>进阶</h3><p>以上内容就好比是内功，有了好的内功，其他的都好学，在之前的REQUEST我们了解到了method和params，那么我们来看看都有哪些外功. 外功分为v2、v4、v6、v8几个版本，目前最新的是v8，可以通过上面给出的例子，获取到当前版本. 竟然我用到的是v8，我们就来看下<a href="http://kodi.wiki/view/JSON-RPC_API/v8" target="_blank" rel="noopener">v8</a>的定义。 v8是随着kodi v17一同发布的，它支持WebSocket。正所谓举其一可知大概，我在这里就不对所有的method进行介绍，我会抽出几个，告知大家如何看懂文档。</p>
<ul>
<li>Player.GetActivePlayers - 获取当前激活的播放器</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">5.9.1 Player.GetActivePlayers</span><br><span class="line">Returns all active players</span><br><span class="line">Permissions:</span><br><span class="line">    ReadData</span><br><span class="line">Returns:</span><br><span class="line">    Type: array</span><br></pre></td></tr></table></figure>
<p>Permissions 权限，可通过JSONRPC.Permission获取权限开关状态<br>Returns：返回</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">curl -X POST --header &quot;content-type:application/json&quot; --data &apos;&#123;&quot;jsonrpc&quot;: &quot;2.0&quot;, &quot;method&quot;: &quot;Player.GetActivePlayers&quot;, &quot;id&quot;:&quot;22&quot;&#125;&apos; http://localhost:8080/jsonrpc</span><br><span class="line"></span><br><span class="line">&#123;&quot;id&quot;:&quot;22&quot;,&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;result&quot;:[&#123;&quot;playerid&quot;:0,&quot;type&quot;:&quot;audio&quot;&#125;]&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>Application.SetVolume - 设置音量</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">5.2.4 Application.SetVolume</span><br><span class="line">Set the current volume</span><br><span class="line">Permissions:</span><br><span class="line">    ControlPlayback</span><br><span class="line">Parameters:</span><br><span class="line">    mixed volume</span><br><span class="line">Returns:</span><br><span class="line">    Type: integer</span><br></pre></td></tr></table></figure>
<p>例子：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"> curl -X POST --header &quot;content-type:application/json&quot; --data &apos;&#123;&quot;jsonrpc&quot;: &quot;2.0&quot;, &quot;method&quot;: &quot;Application.SetVolume&quot;, &quot;params&quot;:&#123;&quot;volume&quot;:8&#125;, &quot;id&quot;:&quot;22&quot;&#125;&apos; http://localhost:8080/jsonrpc</span><br><span class="line"> </span><br><span class="line">&#123;&quot;id&quot;:&quot;22&quot;,&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;result&quot;:8&#125;</span><br></pre></td></tr></table></figure>
<h3 id="扩展"><a href="#扩展" class="headerlink" title="扩展"></a>扩展</h3><p>当然KODI还提供了kodi-send命令，来简化请求，格式如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kodi-send -a &quot;XXX&quot;</span><br></pre></td></tr></table></figure>
<p>xxx见<a href="http://kodi.wiki/view/List_of_built-in_functions" target="_blank" rel="noopener">http://kodi.wiki/view/List_of_built-in_functions</a></p>
<p>如</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">osmc@osmc:~$ kodi-send -a &quot;SetVolume(10)&quot;</span><br><span class="line">Sending action: SetVolume(10)</span><br></pre></td></tr></table></figure>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/03/15/2017-03-15-解决Github Page无法更新/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/03/15/2017-03-15-解决Github Page无法更新/" itemprop="url">解决Github Page无法更新</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-03-15T00:00:00+08:00">
                2017-03-15
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/版本管理/" itemprop="url" rel="index">
                    <span itemprop="name">版本管理</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>春节后，写了一篇文章提交到Github，发现pages没有更新，原先以为Github问题，等了2天，发现一直不更新，于是去查了下什么原因，原来Github在构建pages失败时，会发送邮件给你的邮箱（由于设置了另外一个邮件，因此一直没察觉），查看邮件（也可以进入repo设置界面查看），发现真的是构建失败，给出的提示是<code>Your site is having problems building: Page build failed. For more information, see https://help.github.com/articles/troubleshooting-github-pages-builds/.</code>于是点击相应连接，了解到<code>Page build failed</code>是构建失败，具体原因可以尝试在本地构建。Github给出了<a href="https://help.github.com/articles/setting-up-your-github-pages-site-locally-with-jekyll/#platform-linux" target="_blank" rel="noopener">本地构建方法</a></p>
<p>这里总结构建过程下：</p>
<h5 id="1-安装bunder"><a href="#1-安装bunder" class="headerlink" title="1. 安装bunder"></a>1. 安装bunder</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">gem install bunder</span><br></pre></td></tr></table></figure>
<h5 id="2-安装jekyll"><a href="#2-安装jekyll" class="headerlink" title="2. 安装jekyll"></a>2. <a href="http://jekyllrb.com/" target="_blank" rel="noopener">安装jekyll</a></h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">gem install jekyll bundler</span><br></pre></td></tr></table></figure>
<h5 id="3-在工程主目录生成Gemfile，内容如下"><a href="#3-在工程主目录生成Gemfile，内容如下" class="headerlink" title="3. 在工程主目录生成Gemfile，内容如下"></a>3. 在工程主目录生成Gemfile，内容如下</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">source &apos;https://rubygems.org&apos;</span><br><span class="line">gem &apos;github-pages&apos;, group: :jekyll_plugins</span><br></pre></td></tr></table></figure>
<h5 id="4-构建"><a href="#4-构建" class="headerlink" title="4. 构建"></a>4. 构建</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">bundle exec jekyll serve</span><br></pre></td></tr></table></figure>
<p>构建完后报出了如下错误：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">  Conversion error: Jekyll::Converters::Markdown encountered an error while converting &apos;_posts/2015-06-05-Ruby学习路程.md&apos;:</span><br><span class="line">                    Can&apos;t handle generic non-integer character reference &apos;laquo_space&apos;</span><br><span class="line">jekyll 3.4.1 | Error:  Can&apos;t handle generic non-integer character reference &apos;laquo_space&apos;</span><br></pre></td></tr></table></figure>
<p>提示还是比较明显的，是原来的一篇文章语法错误，原来是标题使用了\&lt;\&lt;（至于为何现在才报错，应该是Github所用的jekyll更新了，而新版jekyll不支持该语法）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">### 5. \&lt;\&lt; self 理解</span><br></pre></td></tr></table></figure>
<p>于是添加转义符修正，并提交更新到Github，发现更新正常了。</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/03/10/2017-03-10-为何请求总是延时5s/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/03/10/2017-03-10-为何请求总是延时5s/" itemprop="url">为何请求总是延时5s</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-03-10T00:00:00+08:00">
                2017-03-10
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/运维/" itemprop="url" rel="index">
                    <span itemprop="name">运维</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <blockquote>
<p>引言：本文描述了我对于”为何请求总是延时5s”问题的分析、解决过程.</p>
</blockquote>
<h2 id="1-初识"><a href="#1-初识" class="headerlink" title="1. 初识"></a>1. 初识</h2><p>最近公司项目遇到一个比较奇怪的问题，现象是在我们的系统（centos6）中发的请求包，总是需要延时5s才能成功. 一想到超时，第一感觉应该就是网络差，于是通过<code>curl www.baidu.com</code>验证，发现也是延时5s才返回，因此第一个结论：网络差</p>
<p>为了进一步确认，尝试在同一网络下其他PC机（Windows）上访问百度网页，发现比较快，并确定不是缓存，于是就有了第一个疑问，”为什么相同网络下不同PC访问百度的时间差别这么大？”</p>
<h2 id="2-误打误撞"><a href="#2-误打误撞" class="headerlink" title="2. 误打误撞"></a>2. 误打误撞</h2><p>针对第一个疑问，对比了PC机的网络配置，是完全一样的，这就无法解释了。就在没有方向的时候，尝试用IP访问，<code>curl 163.177.151.109</code>，发现速度很快，突然想到我们的请求也是使用域名. 于是自然就转向了DNS，是不是DNS解析慢，于是尝试更换了几个DNS（114.114.114.114、8.8.8.8），可是发现问题依旧.</p>
<h2 id="3-DNS充电"><a href="#3-DNS充电" class="headerlink" title="3. DNS充电"></a>3. DNS充电</h2><p>既然问题已经定位在与DNS有关，于是我查阅了资料，了解了DNS的工作流程，如下：</p>
<p><img src="/images/dns-interaction.png" alt="image"></p>
<ul>
<li>递归查询 - A找B要东西；B发现自己没有，B找C要；C给B；B再给A</li>
<li>迭代查询 - A找B要东西；B发现自己没有于是告知A，C有；A找C要，C给A</li>
</ul>
<p>递归查询一般用于本地DNS服务器，迭代查询用于DNS服务器之间</p>
<p>言归正传，于是我使用<code>nslook www.baidu.com</code>发现可以快速返回，因此猜测DNS可以正常获取</p>
<h2 id="4-再抓包"><a href="#4-再抓包" class="headerlink" title="4. 再抓包"></a>4. 再抓包</h2><p>为了找出原因，我使出了杀手锏，用tcpdump抓包，<code>tcpdump -nn host 114.114.114.114</code></p>
<pre>
00:27:09.459055 IP 192.168.1.88.49776 > 114.114.114.114.53: 33750+ A? www.baidu.com. (31)
00:27:09.459067 IP 192.168.1.88.49776 > 114.114.114.114.53: 46955+ AAAA? www.baidu.com. (31)
00:27:09.482865 IP 114.114.114.114.53 > 192.168.1.88.49776: 33750 3/0/0 CNAME www.a.shifen.com., A 14.215.177.37, A 14.215.177.38 (90)
00:27:14.459055 IP 192.168.1.88.49776 > 114.114.114.114.53: 33750+ A? www.baidu.com. (31)
00:27:14.482865 IP 114.114.114.114.53 > 192.168.1.88.49776: 33750 3/0/0 CNAME www.a.shifen.com., A 14.215.177.37, A 14.215.177.38 (90)
00:27:14.459067 IP 192.168.1.88.49776 > 114.114.114.114.53: 46955+ AAAA? www.baidu.com. (31)
00:27:14.482898 IP 114.114.114.114.53 > 192.168.1.88.49776: 46955 1/1/0 CNAME www.a.shifen.com. (115)
</pre>
发现客户端发起A、AAAA的查询，但服务端只回了A，没有回AAAA，于是客户端等待超时后，继续单条单条查询，成功返回. 为了对比，我们再正常PC上也抓包，结果如下：

<pre>
00:27:09.459055 IP 192.168.1.88.49776 > 114.114.114.114.53: 33750+ A? www.baidu.com. (31)
00:27:09.459067 IP 192.168.1.88.49776 > 114.114.114.114.53: 46955+ AAAA? www.baidu.com. (31)
00:27:09.482865 IP 114.114.114.114.53 > 192.168.1.88.49776: 33750 3/0/0 CNAME www.a.shifen.com., A 14.215.177.37, A 14.215.177.38 (90)
00:27:09.482898 IP 114.114.114.114.53 > 192.168.1.88.49776: 46955 1/1/0 CNAME www.a.shifen.com. (115)
</pre>

<p>因此初步断定，是由于无法获取到ipv6地址导致延时，于是通过<code>curl -4 www.baidu.com</code>发现确实没有延时. 可是为什么会获取不到ipv6呢，单条发送是可以正常返回，于是猜到可能是防火墙再搞鬼. 这其中正好发现了这篇《<a href="http://coolnull.com/3820.html" target="_blank" rel="noopener">centos 6中single-request-reopen参数说明</a>》文章</p>
<p><img src="http://static.coolnull.com/wp-content/uploads/2015/05/v3.png" alt="image"></p>
<h2 id="5-结论"><a href="#5-结论" class="headerlink" title="5. 结论"></a>5. 结论</h2><p>综上所述，最终原因出在了防火墙上，但目前防火墙配置不在我们这边，暂时还无法得知，但应该基本可以确定是防火墙搞的鬼，具体的解决方案<code>在/etc/resolv.conf添加以下参数options single-request-reopen</code></p>
<h2 id="6-总结"><a href="#6-总结" class="headerlink" title="6. 总结"></a>6. 总结</h2><p>以上是描述了我对”为何请求总是延时5s”问题的追踪过程，从中学到了DNS解析流程、dig命令，可谓甚丰.</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/01/13/2017-01-13-SIP信令裁剪/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/01/13/2017-01-13-SIP信令裁剪/" itemprop="url">SIP信令裁剪</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-13T00:00:00+08:00">
                2017-01-13
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/音视频/" itemprop="url" rel="index">
                    <span itemprop="name">音视频</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>引言：对于UDP来说，若包大小超过MTU（一般1500）,需要分包发送，而UDP本来就无法保证顺序及可达率，因此发送大于MTU的数据出错概率就非常高；因此对于UDP传输，数据必须控制在MTU以内，而一些SIP信令（如INVITE）基本快接近这个值，倘若多些音视频编码，那必然超出，因此需要对其进行裁剪，本文将为大家阐述如何裁剪SIP信令。</p>
<p>首先，我们需要明确裁剪的方向，裁剪大致包含如下几个方向：</p>
<ul>
<li>头部采用紧凑模式</li>
<li>移除非必要字段</li>
<li>缩短字段内容</li>
<li>移除非必要编码</li>
</ul>
<h3 id="1-信令采用紧凑模式"><a href="#1-信令采用紧凑模式" class="headerlink" title="1. 信令采用紧凑模式"></a>1. 信令采用紧凑模式</h3><p>应该也是处于MTU限制，SIP协议给出了解决方法，即部分头部可以用一个字段替代，具体如下：</p>
<p>头部|缩写<br>|:–|:–<br>Accept-Contact|a<br>Referred-By|b<br>Content-Type|c<br>Content-Encoding|e<br>From|f<br>Call-ID|i<br>Supported|k<br>Content-Length|l<br>Contact|m<br>Event|o<br>Refer-To|r<br>Subject|s<br>To|t<br>Allow-Events|u<br>Via|v</p>
<p>详见<a href="http://www.cs.columbia.edu/sip/compact.html" target="_blank" rel="noopener">这里</a></p>
<h3 id="2-移除非必要字段"><a href="#2-移除非必要字段" class="headerlink" title="2. 移除非必要字段"></a>2. 移除非必要字段</h3><p>此部分内容会不断完善，目前已经知道的是Allow、Supported字段可以省略</p>
<h3 id="3-缩短字段内容"><a href="#3-缩短字段内容" class="headerlink" title="3. 缩短字段内容"></a>3. 缩短字段内容</h3><p>内容可以缩短的尽量采用缩短形式，比如User-Agent的值可以尽量短</p>
<pre>
User-Agent: ios/1 (belle-sip/1.5.0)
</pre>

<h3 id="4-移除非必要编码"><a href="#4-移除非必要编码" class="headerlink" title="4. 移除非必要编码"></a>4. 移除非必要编码</h3><p>可以根据系统的特点，将不需要的音视频编码移除，这样就能够缩短SDP长度，从而缩短SIP长度</p>
<p>以上是裁剪的4个方向，裁剪后一般可以缩短100~200字节</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://smallmuou.gitee.io/blog/blog/2017/01/03/2017-01-03-类Unix下语言环境locale/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="smallmuou">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="smallmuou's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/2017/01/03/2017-01-03-类Unix下语言环境locale/" itemprop="url">类Unix下语言环境locale</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-03T00:00:00+08:00">
                2017-01-03
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/SHELL/" itemprop="url" rel="index">
                    <span itemprop="name">SHELL</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>引言：在使用类Unix系统时，经常会遇到无法显示中文字符，各种乱码，于是Google，找到了若干解决方案，各种设置LC_CTYPE、或者LC_ALL、又或者LANG，然后经过多种答案的叠加，问题就解决，可对其中的原理仍无法理解，可能每次遇到乱码的情况还不一样，解决方法也不一样，于是就更晕.我最近也遇到关于中文字符显示成？的问题，于是想更深入的了解下其中的原理，找到了一篇<a href="http://www.cnblogs.com/xlmeng1988/archive/2013/01/16/locale.html" target="_blank" rel="noopener">好文</a>，现在我再整理下.</p>
<h2 id="1-风俗-locale"><a href="#1-风俗-locale" class="headerlink" title="1. 风俗(locale)"></a>1. 风俗(locale)</h2><p>在人类的世界里，不同地域的人有着不同的风俗，而计算机是给人用的，那自然也要遵循着这一套规则，而这套规则就是locale，我们执行下<code>locale</code>命令：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">smallmuou:locales $ locale</span><br><span class="line">LANG=en_US.UTF-8</span><br><span class="line">LC_CTYPE=zh_CN.utf8</span><br><span class="line">LC_NUMERIC=&quot;en_US.UTF-8&quot;</span><br><span class="line">LC_TIME=&quot;en_US.UTF-8&quot;</span><br><span class="line">LC_COLLATE=&quot;en_US.UTF-8&quot;</span><br><span class="line">LC_MONETARY=&quot;en_US.UTF-8&quot;</span><br><span class="line">LC_MESSAGES=&quot;en_US.UTF-8&quot;</span><br><span class="line">LC_PAPER=&quot;en_US.UTF-8&quot;</span><br><span class="line">LC_NAME=&quot;en_US.UTF-8&quot;</span><br><span class="line">LC_ADDRESS=&quot;en_US.UTF-8&quot;</span><br><span class="line">LC_TELEPHONE=&quot;en_US.UTF-8&quot;</span><br><span class="line">LC_MEASUREMENT=&quot;en_US.UTF-8&quot;</span><br><span class="line">LC_IDENTIFICATION=&quot;en_US.UTF-8&quot;</span><br><span class="line">LC_ALL=</span><br></pre></td></tr></table></figure>
<h2 id="2-表示"><a href="#2-表示" class="headerlink" title="2. 表示"></a>2. 表示</h2><p>『我说中文，国籍是中华人民共和国，使用国标2312字符集来表达字符』这是我的介绍，locale表示方法类似，格式如下：</p>
<p><pre><br>语言[_地域[.字符集]]<br></pre><br>如：zh_CN.GB2312</p>
<p>可以使用<code>locale -a</code>来查看系统支持的所有字符集. 如果字符集缺省，则采用默认值，可以通过<code>locale -v -a</code>查看，如</p>
<p><pre></pre></p>
<h2 id="locale-zh-CN-archive-usr-lib-locale-locale-archive"><a href="#locale-zh-CN-archive-usr-lib-locale-locale-archive" class="headerlink" title="locale: zh_CN           archive: /usr/lib/locale/locale-archive"></a>locale: zh_CN           archive: /usr/lib/locale/locale-archive</h2><pre><code>title | Chinese locale for Peoples Republic of China
email | bug-glibc-locales@gnu.org
</code></pre><p> language | Chinese<br>territory | P.R. of China<br> revision | 0.1<br>     date | 2000-07-25<br>  codeset | GB2312</p>
<p>…</p>
<h2 id="locale-zh-CN-gb2312-archive-usr-lib-locale-locale-archive"><a href="#locale-zh-CN-gb2312-archive-usr-lib-locale-locale-archive" class="headerlink" title="locale: zh_CN.gb2312    archive: /usr/lib/locale/locale-archive"></a>locale: zh_CN.gb2312    archive: /usr/lib/locale/locale-archive</h2><pre><code>title | Chinese locale for Peoples Republic of China
email | bug-glibc-locales@gnu.org
</code></pre><p> language | Chinese<br>territory | P.R. of China<br> revision | 0.1<br>     date | 2000-07-25<br>  codeset | GB2312<br><br>PS: zh_CN与zh_CN.gb2312是等价的</p>
<h2 id="3-分类-Categories"><a href="#3-分类-Categories" class="headerlink" title="3. 分类(Categories)"></a>3. 分类(Categories)</h2><p>风俗可能会包含各方各面，比如吃什么、做什么等等. 而locale同样包含着各个分类，从上面的结果可以看出其包含12个分类(LC_前缀)</p>
<ul>
<li>LC_CTYPE - 用于字符分类和字符串处理，控制所有字符的处理方式，包括字符编码，字符是单字节还是多字节，如何打印</li>
<li>LC_NUMERIC - 数字格式，如小数点、千分位各是什么字符</li>
<li>LC_TIME - 时间格式，如星期、月、上午、下午怎么表示</li>
<li>LC_MESSAGES - 消息格式，如『肯定』、『否定』怎么表示，另外还有一个LANGUAGE参数，它与LC_MESSAGES相似，但如果该参数一旦设置，则LC_MESSAGES参数就会失效。LANGUAGE参数可同时设置多种语言信息，如LANGUANE=”zh_CN.GB18030:zh_CN.GB2312:zh_CN”</li>
<li>LC_PAPER - 纸张大小，如长、宽多少</li>
<li>LC_TELEPHONE - 电话号码格式，如区号，显示格式</li>
<li>LC_NAME - 名字格式，如miss用『小姐』表示，mr用『先生』表示等</li>
<li>LC_ADDRESS - 地址格式，如国家、城市等</li>
<li>LC_MEASUREMENT - 度量格式</li>
<li>LC_IDENTIFICATION - 该locale的概述</li>
<li>LC_MONETARY - 货币格式，如￥、小数点、千分位</li>
<li>LC_COLLATE - 排序规则</li>
</ul>
<p>具体定义可以到/usr/share/i18n/locates/下对应的文件查看，其中字符采用UNICODE16表示，如zh_CN文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line"></span><br><span class="line">LC_NUMERIC</span><br><span class="line">decimal_point             &quot;&lt;U002E&gt;&quot;    小数点用.表示</span><br><span class="line">thousands_sep             &quot;&lt;U002C&gt;&quot;    千分位用,表示</span><br><span class="line">grouping                  3</span><br><span class="line">END LC_NUMERIC</span><br><span class="line"></span><br><span class="line">LC_TIME</span><br><span class="line">abday 	&quot;&lt;U65E5&gt;&quot;;&quot;&lt;U4E00&gt;&quot;;&quot;&lt;U4E8C&gt;&quot;;&quot;&lt;U4E09&gt;&quot;;&quot;&lt;U56DB&gt;&quot;;&quot;&lt;U4E94&gt;&quot;;&quot;&lt;U516D&gt;&quot;  星期缩写：日、一、二、三、四、五、六</span><br><span class="line"></span><br><span class="line">day 	&quot;&lt;U661F&gt;&lt;U671F&gt;&lt;U65E5&gt;&quot;;/   星期日</span><br><span class="line">	&quot;&lt;U661F&gt;&lt;U671F&gt;&lt;U4E00&gt;&quot;;/		星期一</span><br><span class="line">...</span><br></pre></td></tr></table></figure>
<h2 id="4-改进"><a href="#4-改进" class="headerlink" title="4. 改进"></a>4. 改进</h2><p>有了以上的locale及categories就能满足了【不同地域不同风俗】的需求，但考虑到方便性，系统又引入LC_ALL、LANG这两个环境变量</p>
<ul>
<li>LC_ALL - 全局设定</li>
<li>LANG - 默认设定</li>
</ul>
<p>有了以上两个值，于是又引入了如下规则</p>
<ul>
<li>规则一：优先级：<code>LC_ALL &gt; LC_* &gt; LANG</code></li>
<li>规则二：如果LC_ALL、LC_*、LANG都不指定，则采用POSIX作为locale，即 C locale</li>
</ul>
<h2 id="5-总结"><a href="#5-总结" class="headerlink" title="5. 总结"></a>5. 总结</h2><p>有了以上背景，应该就能比较好地了解Unix/Linux的语言环境，其中最重要的三个是：LANG、LC_CTYPE、LC_ALL<br></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/blog/page/8/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/blog/">1</a><span class="space">&hellip;</span><a class="page-number" href="/blog/page/8/">8</a><span class="page-number current">9</span><a class="page-number" href="/blog/page/10/">10</a><span class="space">&hellip;</span><a class="page-number" href="/blog/page/20/">20</a><a class="extend next" rel="next" href="/blog/page/10/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">smallmuou</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">197</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">12</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/smallmuou" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-globe"></i>GitHub</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">smallmuou</span>

  
</div>

    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

    <span id="busuanzi_container_site_pv">总访问量<span id="busuanzi_value_site_pv"></span>次</span>
    <span class="post-meta-divider">|</span>



  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  

  

  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
